// Setup basic express server
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var port = process.env.PORT || 3000;

server.listen(port, function () {
  console.log('Server listening at port %d', port);
});

// Routing
app.use(express.static(__dirname + '/public'));

// Chatroom

var numUsers = 0;

var zmq = require('zmq');
var sock = zmq.socket('sub');

sock.bindSync('tcp://0.0.0.0:4002');
sock.subscribe('');

sock.on('message', function(msg) {
  // console.log('received',msg.toString());
  io.emit('msg', msg.toString());
});

// sock.on('message', function(msg) {
//   console.log('received2',msg.toString());
//   socket.broadcast.emit('msg', msg.toString());
// });

// io.on('connection', function (socket) {
// });

